package com.ivr.cm.dao.impl;

import org.springframework.jdbc.core.support.JdbcDaoSupport;

import com.ivr.cm.dao.IDispatcherResultDao;
import com.ivr.cm.service.BaseServiceIF;
import com.ivr.cm.util.BaseUtil;
import com.ivr.cm.vo.DispatcherResultVo;

public class DispatcherResultDaoImpl extends JdbcDaoSupport implements IDispatcherResultDao, BaseServiceIF<Object> {

	@Override
	public int doProcess(Object obj) {
		if(obj instanceof DispatcherResultVo){
			return insertDispatcherResult((DispatcherResultVo)obj);
		}
		return 0;
	}

	@Override
	public int insertDispatcherResult(DispatcherResultVo dispatcherResultVo) {
		String sql = "insert into tb_ivr_dispatcher_result(mobile,linkid,sync_url,parameter,type,lower_id,router_id,status_code,dis_count) values(?,?,?,?,?,?,?,?,?)";
		Object[] param = new Object[]{dispatcherResultVo.getMobile(),dispatcherResultVo.getLinkId(),
									dispatcherResultVo.getSync_url(),dispatcherResultVo.getParameter(),
									dispatcherResultVo.getType(),dispatcherResultVo.getLower_id(),
									dispatcherResultVo.getRouter_id(),dispatcherResultVo.getStatus_code(),
									dispatcherResultVo.getDis_count()};
		logger.info(String.format("保存账单转发数据[%s]", BaseUtil.logSQL(sql, param)));
		int count = this.getJdbcTemplate().update(sql, param);
		return count;
	}
}